unit Login;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RzButton, StdCtrls, Mask, RzEdit, RzLabel, RzBorder, ExtCtrls,
  RzPanel, DB, ADODB, PngImage1;

type
  TfrmLogin = class(TForm)
    RzPanel1: TRzPanel;
    RzLabel1: TRzLabel;
    RzLabel2: TRzLabel;
    RzBorder1: TRzBorder;
    RzLabel3: TRzLabel;
    RzLabel4: TRzLabel;
    RzURLLabel1: TRzURLLabel;
    edtUserLogin: TRzEdit;
    edtUserPassword: TRzEdit;
    RzBitBtn1: TRzBitBtn;
    QryCheckLogin: TADODataSet;
    dsCheckLogin: TDataSource;
    ADOConnection1: TADOConnection;
    procedure RzBitBtn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmLogin: TfrmLogin;

implementation

uses Main;

{$R *.dfm}

procedure TfrmLogin.RzBitBtn1Click(Sender: TObject);
var
AFrmMain:TfrmMainWindow;
begin

    if trim(edtUserLogin.Text)='' then
    begin
       Application.MessageBox('Please enter a user login.', 'User required', MB_ICONEXCLAMATION);
       edtUserLogin.SetFocus;
       Exit;
    end;
    if trim(edtUserPassword.Text)='' then
    begin
       Application.MessageBox('Please enter a password login.', 'Password required', MB_ICONEXCLAMATION);
       edtUserPassword.SetFocus;
       Exit;
    end;

    if QryCheckLogin.Locate('username',trim(edtUserLogin.Text),[])= false then
    begin
       Application.MessageBox('User not found.', 'User not found', MB_ICONEXCLAMATION);
       edtUserLogin.SetFocus;
       Exit;
    end;

    if QryCheckLogin.Locate('password',trim(edtUserPassword.Text),[])= false then
    begin
       Application.MessageBox('Password is not correct.', 'Password Incorrect', MB_ICONEXCLAMATION);
       edtUserPassword.SetFocus;
       Exit;
    end;

    AFrmMain:= TfrmMainWindow.Create(nil);
    AFrmMain.ADOConnection1:=ADOConnection1;
    AFrmMain.iDefUser:= QryCheckLogin.Lookup('username',trim(edtUserLogin.Text),'EMPLOYEECODE');
    AFrmMain.iDefUserFName:= QryCheckLogin.Lookup('username',trim(edtUserLogin.Text),'DTRLINKNAME');
    AFrmMain.ShowModal;
    AFrmMain.Caption:= 'HRIS : Task Management (' +   AFrmMain.iDefUserFName + ')';
    AFrmMain.Free;
    Close;

    //Provider=SQLOLEDB.1;Password=Gems@2014;Persist Security Info=True;User ID=sa;Initial Catalog=HRIS;Data Source=tcp:192.168.0.111\SQLEXPRESS,1433;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=TOSHIBA;Use Encryption for Data=False;Tag with column collation when possible=False

end;

procedure TfrmLogin.FormShow(Sender: TObject);
var
sCGConn,sLocalConn,sLocalCEBUGEMSHRIS:string;
begin
  sCGConn := 'Provider=SQLOLEDB.1'
          + ';Password=Gems@2014'
          + ';Persist Security Info=True'
          + ';User ID=sa'
          + ';Initial Catalog=HRIS'
          + ';Data Source=tcp:192.168.0.111\SQLEXPRESS,1433';
  sLocalConn := 'Provider=SQLOLEDB.1'
           + ';Password=mdoffice'
           + ';Persist Security Info=True'
           + ';User ID=sa'
           + ';Initial Catalog=HRIS'
           + ';Data Source=TOSHIBA\SQLEXPRESS';

  sLocalCEBUGEMSHRIS := 'Provider=SQLOLEDB.1'
           + ';Password=mdoffice'
           + ';Persist Security Info=True'
           + ';User ID=sa'
           + ';Initial Catalog=CEBUGEMSHRIS'
           + ';Data Source=TOSHIBA\SQLEXPRESS';

    ADOConnection1.Close;
    ADOConnection1.ConnectionString:=sCGConn;
    ADOConnection1.Connected:=true;
    QryCheckLogin.Open;
end;

end.
